Skip to content

Fix agent apply patching gem homes Bundler never loads (#2313) - #2402

Merged
Mikola Lysenko (mikolalysenko) merged 24 commits into
mainfrom
agent/fix-gem-apply-unused-system-homes
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 24 commits into
mainfrom
agent/fix-gem-apply-unused-system-homes

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2313

Root cause

Agent apply takes its gem write targets from the crawler's gem paths. Those keep every gem env home whenever the default vendor/bundle root holds no store, so that default gems (which only live there) can be patched. Nothing then limited the copies found in those homes to default gems. Under an explicit or deployment Bundler path, Bundler never loads a non-default gem from a gem env home, so apply wrote a copy that belongs to other projects on the machine, and on a fresh clone reported success while the project had no patched gem. The read-only side (vex, apply --check) already applied the right rule.

The maintainer's decision (2026-12-01): yes

The behavior #2313 reports was the documented contract ("Copy classes" in CLI_CONTRACT.md) and was pinned by tests/apply/in_process_gem_fallback_home.rs, so the fix waited for a ruling. The ruling: agent apply stops writing non-default gem copies in gem env homes that Bundler does not load from for the project; rollback and remove keep finding them, since an earlier release may have patched them.

What changes

  • One rule, one place. retain_bundler_loaded_gem_copies (ecosystem_dispatch.rs) is the rule vex and apply --check already used, lifted out of them. apply's resolver now calls it too. Under a path or deployment mode, a copy in a gem env home is a write target only when it is a default gem (json, uri, set) or Bundler itself, which the project loads from the gem home under any path. A bundled gem (rexml, rake) follows the ordinary rule.
  • A fresh clone is not a success. With nothing installed in the path yet, a gem Gemfile.lock lists is reported as not installed (1 not found on disk, exit 0), and the shared copy is not touched.
  • Scan and get select by the same rule. This goes one step past the ruling, which left the scan's discovery alone: measured on a real project, leaving it alone turned a scan that exits 0 on main into exit 1, because the scan selected a patch that apply then refused to write. An agent-mode scan, and get by name or by advisory, no longer select a gem that only another project's gem home holds. A gem the lock lists whose only copy is in such a home takes the existing not-installed path, as it does when no gem home holds it. get with an exact purl is unchanged.
  • Records an earlier release wrote. Releases up to 5.1.0 recorded patches for other projects' gems. When the project's Bundler lock was read and does not list the gem, apply skips such a record with a gem_other_project_copy_skipped warning that names the copy and socket-patch rollback <purl>, counts it as not applicable and exits 0. Without a lock to go by (no Gemfile.lock, or a layout the CLI does not read), the gem may be the project's own, so it is reported as not installed, as any package is. scan --sync keeps the record, so that rollback can still restore the copy.
  • rollback leaves a copy that holds nothing of the patch. A copy in a gem home the project does not load is restored only when it holds the patch. Before, a diverged copy there failed the rollback with hash_mismatch.

What it does not change

  • No path (system gems): Bundler loads the project's gems from the shared homes, and apply patches them there, as before.
  • A populated vendor/bundle: apply looks only there, as before.
  • apply --global patches the shared homes whatever the project's Bundler settings are.
  • rollback and remove restore a patched copy in a shared home even when another project, with no path of its own, patched it with the same patch: the two cannot be told apart. The contract and the Ruby guide now say so.

Measured (real Bundler 4.0.15, Ruby 3.4.10, rack 2.2.8 only in the gem home, path vendor/gems)

Run main This branch
scan --mode agent, lock does not list rack exit 0, the other project's copy patched exit 0, rack not queried, nothing recorded
scan --mode agent, lock lists rack, path empty exit 0, the shared copy patched, "applied" exit 0, package_not_installed, nothing downloaded or recorded
apply, scan, rollback over a record 5.1.0 wrote for the other project's rack exit 0, patched again exit 0 each: skipped with the warning; rollback restores the copy
get rack exit 0, patched exit 0, "No packages matching"
apply, gem installed in the path and in the gem home both patched (applied: 2) the project's copy patched (applied: 1), the shared copy untouched
apply over a record, no Gemfile.lock, rack only in the gem home, nothing else matched exit 0, the shared copy patched exit 1, package_not_installed

The first four rows were measured with real runs before the last round of review fixes, and the scan and get rows again after the first round; the fifth is from the in-process tests and the sixth from a test of the last round. The warning in the third row is gem_other_project_copy_skipped on the final head.

For a maintainer

  1. Scan and get follow the rule, beyond the ruling, for the reason above. The alternative was a scan that fails on another project's gem.
  2. An old record for another project's gem is a warning with exit 0, not exit 1. A run that matched nothing because a gem is installed nowhere and locked nowhere still exits 1, as for any package.
  3. Every installed Bundler version in a gem home counts as loaded, not only the one that would run: which one runs also depends on BUNDLER_VERSION and Bundler's own version switch, and a wrong guess would leave the running Bundler unpatched.
  4. get pkg:gem/<name>@<version> for another project's gem records the patch and takes the skip (exit 0); its variant is still picked by hashing that copy.
  5. A project with no lock (a gem library that commits none) that has a record, a path and nothing installed in it yet gets exit 1 from apply where main patched the shared copy and exited 0 (last row of the table). Without a lock the CLI cannot tell the project's gem from another project's, so it says not installed and gives no rollback advice.
  6. A shared copy that 5.1.0 patched beside the project's own copy stays patched after the upgrade, and apply does not mention it. The guide names the remedy: socket-patch rollback <purl> --preserve-state, then socket-patch apply.
  7. A gem the lock holds only as platform builds, whose only copy is in a shared home, is not reported by an agent-mode scan (stated in the contract).

Review

/code-review high on the first version returned seven findings. Fixed: get did not follow the rule; an old record made apply exit 1 with the wrong remedy; an updated Bundler was treated as another project's gem; a locked gem whose only copy is in a shared home was recorded and then reported not installed in the same run; rollback failed on a diverged shared copy; the docs named rexml as a default gem. Not changed, by the ruling: rollback and remove restore a shared copy another project patched with the same patch (stated in the contract).

A second /code-review high, on the head with those fixes, returned six. Fixed: the other-project skip was also taken by a project with no lock the CLI reads, and advised a rollback of a patch the project needs; get <name> --save-only ran the filter although it applies nothing; Bundler was identified by a directory-name prefix that bundler-2fa would match; one warning code carried two meanings, so the other-project skip has its own, gem_other_project_copy_skipped. Documented and not changed: items 6 and 7 above.

Tests

  • New: tests/scan/scan_gem_unloaded_homes.rs, tests/get/get_gem_unloaded_homes.rs; tests/apply/in_process_gem_fallback_home.rs is rewritten (its best-effort skips now use a default-gem copy).
  • Run locally on the head commit, after main was merged in: cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, and the CLI lib (1086), apply (225), scan (274), get (167), rollback (142), remove (90), vendor (146) and vex (29) suites, the core Ruby crawler tests, and the stale-install and native-extension gem suites (with their real-Ruby capstones), all passing. Not run locally: the suites that need the network, Docker or the live API.
  • Windows: PR runs have no Windows test job, so the Windows tier was run by dispatch. It first failed with a stack overflow in remove_base_purl_clears_all_platforms_and_rolls_back (in_process_gem_multi_platform), which main has too since 0a1709bb2 (run on main). This branch boxes the checks it added and the four hand-offs of the scan to gem apply chain (bad4acf47, 1c74732b2), and passes: run 46788431120 on 1c74732b2, all 48 jobs. Run each copy's patch engine behind a pointer, so the in-process gem tests fit their stack on Windows #2432 fixes the same overflow in the core engines for main.

Windows stack overflow in the in-process gem test

The dispatched Windows run failed twice on this branch in remove_base_purl_clears_all_platforms_and_rolls_back ("has overflowed its stack"). The overflow is in the test's first step, the in-process scan that downloads and applies. That chain (scan, download, nested apply, apply loop, gem patch) is the CLI's deepest, and on main it already takes 1996 KiB of the 2048 KiB test thread (smallest passing RUST_MIN_STACK, Linux debug build). This branch took 1999.

Commit 1c74732 boxes the four hand-offs of that chain, so each caller's poll frame holds a pointer instead of the callee's future. The same test now needs 1816 KiB, 180 below main. The futures and their order are unchanged, and the shipped binary was never affected (its main thread has 8 MiB on every platform).

Checked locally on 1c74732: cargo fmt --check on the three files, cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings, the CLI lib tests (1090), apply (225), scan (274), get (167), in_process_agent_patch_replace (14) and in_process_gem_multi_platform (9), all passing. The Windows-only CI run dispatched on 1c74732 passed, both test shards included. The same test now also overflows on main at 0a1709b in its own Windows run (test (windows-latest, 2)), so this commit clears that failure for main as well once it merges.

The other failure in that Windows run, composer_crawler::tests::equivalence::randomized_vendor_trees_match_the_async_oracle in test (windows-latest, 1), is in code this branch does not touch and passed in the earlier Windows run of this branch.


Generated by Claude Code

Agent apply writes gem copies in gem env homes that Bundler never
loads for a project with an explicit install path. Work in progress
for #2313.

Assisted-by: Claude Code:claude-fable-5-2
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aePyMvbD6rKimV9v2pL
`find_manifest_package_copies_reusing` dropped the gem copies Bundler
never loads for the project inline: a copy in a `gem env` home under an
explicit or deployment `path`, unless it is a default gem. Move that
into `retain_bundler_loaded_gem_copies`, beside the Cargo twin, so the
forward writer can use the same rule (#2313).

The helper returns before the `gem env` probe when every copy sits in
one of the project's own Bundler stores. No behaviour change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Under an explicit Bundler `path` (app config, `BUNDLE_PATH`) or
deployment mode, Bundler installs every non-default gem into that path
and never loads one from a `gem env` home (the system gems, an rbenv or
asdf home, `~/.gem`). Agent `apply`, and the apply that `get` and
`scan --mode agent` run, still wrote every copy of the patched version
it found in those homes: a gem that belongs to other projects on the
machine. On a fresh clone, with nothing in the path yet, it printed
"N of N targeted patches applied" while the project had no patched gem.

`find_all_packages_for_purls` now drops those copies by the rule `vex`
and `apply --check` already follow: a copy in a `gem env` home Bundler
does not load from is a write target only when it is a default gem. A
gem left with no copy is `package_not_installed`, as any package that is
not installed: a calm skip when the lock resolves it, the all-miss error
when nothing does. `vendor` asks the same resolver whether a gem already
holds its patch in agent mode, so it keeps agreeing with what `apply`
writes. `rollback` and `remove` resolve without the rule and still
restore such a copy, which an earlier release may have patched.

Unchanged: a populated `vendor/bundle`, Bundler using system gems,
default gems, `--global` runs, and the agent scan's discovery crawl.

The fallback-home tests pinned the old write scope. They now pin the
new one, and keep the best-effort failure semantics on the copies that
are still written (a default gem beside a store copy).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CLI_CONTRACT.md's "Copy classes" paragraph said a copy in a `gem env`
fallback home is patched whenever it matches and is writable. Say when
it is a write target (Bundler using system gems, or a default gem),
what a gem with no copy left reports, and that `rollback`, `remove` and
`--global` runs are unchanged. The best-effort failure rule now reads
on the copies that are still written.

Both texts also say what was already true and unwritten: once the
default `vendor/bundle` holds the project's gems, no local run searches
the `gem env` homes, so a default gem there is not patched and
`rollback` names `rollback <purl> -g` for a copy left patched there.

Add the agent-mode rule to "Ruby gems: gems already installed" in
docs/ecosystems.md, beside the hosted-mode rule for shared gem homes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Agent `apply` no longer writes a non-default gem in a `gem env` home
that Bundler does not load for the project. The scan's crawl still found
such a gem, so `scan --mode agent` selected its patch, downloaded and
recorded it, and its apply step then reported it as not installed. With
no other patch matched the scan exited 1 where it exited 0 before, and
so did every later `apply`, over a gem the project does not use.

The scan now drops such a gem from its candidates when the project's
lock does not list it either: it is not counted, queried or shown, and
nothing is downloaded or recorded for it. The question is put to
`apply`'s own resolver (`gems_apply_never_writes`), so the scan cannot
select what `apply` will not write. The filter runs after the prune
universe is captured: a prune still counts the copy as installed and
keeps a record an earlier release wrote for it, which `rollback`
restores.

Unchanged: a gem the lock lists (a fresh clone before `bundle install`)
is still selected and recorded, and the apply step reports it as not
installed on this host, exit 0. So are default gems, Bundler using
system gems, a populated `vendor/bundle`, and hosted and vendored scans.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The "Copy classes" paragraph of CLI_CONTRACT.md said the scan's
discovery was not narrowed by the write rule. Say that it selects by the
same rule: a gem only another project's gem home holds, and that the
lock does not list, is no candidate, while a gem the lock lists is still
recorded. docs/ecosystems.md says the same for users, and what to do
with a record an earlier release wrote for such a gem.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Bundler is never installed into a project's `path`. A Bundler updated
with `gem install bundler` lives in the system gem home with its spec
outside `specifications/default/`, and `bundle exec` loads it from
there under any path (checked with Bundler 2.6.9 on Ruby 3.4 under
`path vendor/gems`). The rule that drops the gem copies Bundler does
not load treated it as another project's gem, so `apply` stopped
patching it and `vex` and `apply --check` stopped judging it.

`retain_bundler_loaded_gem_copies` now keeps a `bundler-<version>` copy
in a `gem env` home, as it keeps a default gem, so every command that
uses the rule agrees. Every installed version is kept: which one runs
also depends on the lock's `BUNDLED WITH`, on `BUNDLER_VERSION` and on
Bundler's own switch to the locked version, and a wrong guess would
leave the running Bundler unpatched. `bundler-audit` and the like are
ordinary gems.

Two crawler comments gave rexml as an example of a default gem; it has
been a bundled gem since Ruby 3.0, so they now name json and uri.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A manifest record for a gem whose only copy sits in a `gem env` home
that Bundler does not load for the project made `apply` exit 1 with
"matched no installed package" and "Check that the packages are
installed and --cwd points to the right directory". Both are wrong: the
gem is installed, for another project, and the record is one an earlier
release wrote when it patched that copy, or one `get` of the exact purl
wrote. The remedy is `socket-patch rollback <purl>`.

Such a record is now a skip of its own. For the gems `apply` found no
copy to write and no lock lists, it asks `rollback`'s resolver, which
does not apply the rule, whether a copy exists. One that does is a
`skipped` event with the existing `gem_fallback_home_skipped` code: the
detail names the copy, says why it was left, and gives the `rollback`
command, which is true whether or not the copy was ever patched. The
human run prints it as a warning and counts the patch as "not
applicable". It never flips the exit code and is not an all-miss. A gem
with no copy anywhere and no lock entry keeps the all-miss exit 1, and
one the lock lists keeps the lockfile-only skip.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n and get

Two gaps were left after the scan stopped selecting another project's
gems.

A gem the lock lists, with a copy only in a `gem env` home Bundler does
not load, was shown as installed, downloaded and recorded, then
reported as not installed by the apply step of the same run, and its
recorded variant was picked by hashing the other project's copy. The
same gem with no copy at all is lockfile-only: flagged `notInstalled`
and skipped before any download. An agent-mode scan now takes the gems
`apply` has no copy to write out of the crawl before the lockfile
supplement, so both fresh-clone states go down the lockfile-only path
and a gem the lock does not list is no candidate. Their purls stay in
the prune universe, so a record an earlier release wrote is kept until
`rollback` drops it.

`get` in agent mode still took such a gem for an installed package:
`get <name>` resolved it from the crawl, and `get <CVE|GHSA>` kept its
version when narrowing to what is installed. Both now ask the same
question as the scan. An exact purl is not narrowed for any package and
is left alone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`rollback` and `remove` resolve gem copies without the rule `apply`
follows, so that a copy an earlier release patched in a `gem env` home
stays restorable. That also made them judge a copy `apply` never
wrote: one holding neither side of the patch (another project's edit,
or another build) failed the rollback with `hash_mismatch`, and
`apply` no longer says anything about such a copy. It also meant the
`rollback` that `apply` now names for another project's gem failed on
exactly those copies.

A copy that Bundler does not load for the project and that holds
nothing of the patch is now left out of the rollback targets, whatever
it holds. One that holds the patch stays, under every record of its
release, so the variant narrowing still sees it. With no copy left the
record is dropped as for a package that is not installed. The
patched-content test is the one `patched_in_other_scope` already used,
lifted into `copy_holds_patch`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CLI_CONTRACT.md "Copy classes" and the Ruby section of
docs/ecosystems.md now say: Bundler and default gems are patched in the
gem home they are installed in; a record for another project's gem is a
`gem_fallback_home_skipped` skip that names `rollback`, exit 0; a gem
the lock lists with no copy `apply` writes is lockfile-only in a scan,
with nothing recorded; `get` by name or advisory follows the scan;
`rollback` and `remove` leave out a copy that holds nothing of the
patch. The contract's code table gains the `gem_fallback_home_skipped`
row it never had.

Both also state that a copy another project patched with the same
patch in system-gems mode cannot be told from one this project patched,
so `rollback` and `remove` restore it too.

`rexml` was given as an example of a default gem. Since Ruby 3.0 it is
a bundled gem with an ordinary spec, so it follows the ordinary rule:
the examples are now `json`, `uri` and `set`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… skip

The skip for another project's gem asks whether the lock lists the gem
through the lock inventory, which leaves out a gem `Gemfile.lock` holds
only as precompiled platform builds (`nokogiri (1.18.10-x86_64-linux)`).
On a fresh clone with the same version in a gem home, `apply` then said
the gem belongs to another project and named the `rollback` of a patch
the project needs.

Such a gem is the project's. It is taken out of the candidates, so it
keeps the not-installed result it had.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An agent-mode scan takes the gems `apply` has no copy to write out of
its crawl. Their purls must stay in the prune universe: the copy is on
disk and may hold a patch an earlier release wrote, and a prune that
dropped the record and its blobs would leave nothing for `rollback` to
restore it with.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 21:57
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core gem install targeting and multi-command consistency (apply/scan/get/rollback/vex); behavior shifts for users with legacy manifests and shared gem homes, though scoped to Ruby/Bundler agent mode.

Overview
Agent-mode gem apply, scan, and get now only target copies Bundler actually loads for the project. Under an explicit or deployment path, ordinary gems in shared gem env homes are no longer written (they belong to other projects); default gems and Bundler in those homes still are, matching what vex / apply --check already judged.

Unwritable shared copies surface as non-fatal gem_fallback_home_skipped skips (with rollback guidance) instead of failing the run or looking “not installed.” rollback / remove still restore shared copies that hold a patch, but ignore unloaded copies with no patch content—no hash_mismatch on another project’s diverged tree. CLI_CONTRACT.md, docs/ecosystems.md, and broad integration tests document and pin the behavior.

Reviewed by Cursor Bugbot for commit 7c2d9e7. Configure here.

`is_bundler_copy` told Bundler by its gem dir: the prefix `bundler-`
followed by a digit. A gem named like `bundler-2fa` passes that test,
so its copy in a `gem env` home would have been kept as one the project
loads and patched there.

`retain_bundler_loaded_gem_copies` has the purl as its map key, so it
now compares the gem name in it to `bundler`, and the directory test is
gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`--save-only` forces agent mode, so `get <name> --save-only` ran the
filter that leaves out a gem `apply` has no copy to write, and printed
"No packages matching" for a gem that only a `gem env` home holds. It
applies nothing, and `get <GHSA> --save-only` and an exact purl still
recorded the patch.

The name path skips the filter under `--save-only`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`apply` took "not in the lock inventory" as proof that a gem whose only
copy sits in a `gem env` home is another project's. The inventory is
also empty when no lock was read: a project with no lock yet (a gem
library that commits none), and the layouts reported as
`gem_lock_unsupported` (an unsupported `BUNDLE_GEMFILE` or
`BUNDLE_LOCKFILE`, a `Gemfile` + `gems.rb` twin). There `apply` said
the lock does not list the gem and advised a `rollback` that removes a
patch the project may need.

The skip now needs a Bundler lock that was read (`gem_lock_read_in`)
and does not list the gem. Without one the gem keeps the
`package_not_installed` result. The fixtures of the other-project cases
get a lock, and the lockless case is pinned.

`scan` and `get` do not use the lock to drop such a gem: to them a gem
`apply` has no copy to write is not installed, with or without a lock,
and the lock only decides whether it is reported as lockfile-only. They
are unchanged.

The skip also gets its own code, `gem_other_project_copy_skipped`. It
shared `gem_fallback_home_skipped` with the best-effort skip, which is
keyed by the base purl and means the patch is in effect on the copy
bundler loads; this one is keyed by the manifest key and means nothing
was applied, and a consumer could not tell them apart.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CLI_CONTRACT.md and docs/ecosystems.md follow the code: a gem is called
another project's only under a lock that was read, the skip is
`gem_other_project_copy_skipped` with its own table row, and
`get --save-only` records by name.

Two things are stated and not changed. A copy in a shared gem home that
a release up to 5.1.0 patched beside the project's own copy stays
patched after an upgrade, and `apply` does not mention it:
`rollback <purl> --preserve-state` restores both copies and keeps the
record, and the `apply` after it patches the project's copy alone. And
an agent-mode scan does not report a gem the lock holds only as
precompiled platform builds as not installed, with or without a copy in
a `gem env` home.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
With a `gems.rb` beside the `Gemfile`, which pair loads depends on the
Bundler that runs, so the `Gemfile.lock` on disk is not read. A gem
whose only copy sits in a `gem env` home then keeps the not-installed
result, as in a project with no lock: nothing calls it another
project's, and no `rollback` is advised.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 1, 2026
One conflict, in the re-exports of vendor/lock_inventory/mod.rs: this
branch adds gem_lock_read_in, main adds gem_resolved_builds_in. Both are
kept.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
On Windows the in-process test
`remove_base_purl_clears_all_platforms_and_rolls_back` overflowed its
2 MiB test thread stack on this branch and not on main. The branch
awaited its new gem checks inline in `scan_project`,
`rollback_patches_inner`, `apply_patches_inner` and `get`, and inside
`find_all_packages_for_purls`, whose future those callers build in
their own frames. A debug build keeps room in the caller's poll frame
for each such future, also behind an inline `Box::pin(..)`, and those
frames stay on the stack for the whole run, under the deepest chain.

Each of those awaits now goes through `boxed`, which builds the future
in its own frame so the caller holds a pointer: the candidate filter in
scan and get, the rollback target filter, the other-project skip in
apply, and the three calls of the shared rule in the resolvers.

Measured on macOS as the smallest `RUST_MIN_STACK` at which a test
passes (KiB; main, branch before, branch after): the remove test and an
in-process rollback test 1972, 1988, 1972; an in-process scan and apply
1892, 1908, 1892. The CLI's main thread (`ulimit -s`) for a gem
rollback: 1412, 1428, 1412; for a gem apply 1668 throughout.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The Windows run of this branch still overflowed the 2 MiB test thread
in `remove_base_purl_clears_all_platforms_and_rolls_back`. The
overflow is in the test's first step, the in-process scan that
downloads and applies, not in the remove: scan -> download ->
nested apply -> apply loop -> gem patch is the deepest chain of the
CLI, and a debug build keeps each callee's future in its caller's
poll frame.

That chain had no room left before this branch. Measured on Linux as
the smallest `RUST_MIN_STACK` at which the test passes, main needs
1996 KiB of the 2048 and this branch needed 1999, which is enough to
tip a Windows debug build over.

The four hand-offs of the chain now go through `boxed`, so each
caller's frame holds a pointer: the download and apply in scan, the
nested apply in the download engine, `apply_patches_inner`, and the
gem patch in the apply loop. The same test now needs 1816 KiB, 180
below main. Nothing else changes: the same futures run in the same
order. The shipped binary was never at risk, its main thread has
8 MiB on every platform.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f9aeRtYGshMQUt3iHo5jY
Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit d718b07 Dec 2, 2026
137 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-gem-apply-unused-system-homes branch December 2, 2026 02:27
Mikola Lysenko (mikolalysenko) added a commit that referenced this pull request Dec 2, 2026
…s-dir' into fix/vex-pnpm-store-windows

The base branch took in main, which holds #2430 (the rule this branch
extends) and the two fixes for the stack that the in-process gem tests
overflow on Windows (#2402, #2432). Without them the Windows test shard
fails on a test this branch does not touch.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

3 participants